package com.example.demo.entity.vo;

import com.example.demo.entity.pojo.Book;
import com.example.demo.entity.pojo.BookRecord;
import com.example.demo.entity.pojo.Card;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class RecordVo {
    private int id;
    private int sCardId;
    private String bookName;
    private String author;
    private String startTime;
    private String time;
    private String returnTime;
    private String state;
    private String type;
    private int bookId;



    public RecordVo(BookRecord bookRecord, Card card, Book book){
        this.bookId = bookRecord.getBookId();
//        this.id = bookRecord.getId();
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm" );
        this.author = book.getAuthor();
        this.sCardId = card.getNumber();

        this.startTime = sdf.format(bookRecord.getStartTime());
        this.returnTime = sdf.format(bookRecord.getReturnTime());
        this.bookName = book.getName();
        if(bookRecord.getTime() == null){
            this.time = "借出中";
        }else {
            this.time = sdf.format(bookRecord.getTime());
        }

        if (bookRecord.getState() == 1){
            this.state = "正常归还";
        }else if (bookRecord.getState() == 0){
            this.state = "正常借出";
        }
        if (bookRecord.getTime() != null && bookRecord.getTime().getTime() > bookRecord.getReturnTime().getTime()){
            this.state = "逾期归还";
        }
        if (bookRecord.getTime() == null && System.currentTimeMillis() > bookRecord.getReturnTime().getTime()){
            this.state = "逾期借出中";
        }
        if (book.getTypeId() == 1){
            this.type = "小说";
        }
        if (book.getTypeId() == 2){
            this.type = "经典";
        }
        if (book.getTypeId() == 3){
            this.type = "科学";
        }
        if (book.getTypeId() == 4){
            this.type = "言情";
        }
        if (book.getTypeId() == 5){
            this.type = "生活";
        }

    }
}
